package dongchel.vrp.entity;

import java.util.ArrayList;
import java.util.List;

public class MultiObjectiveObject {
	/**
	 * List objectiveList multiObjectiveComparator implements Comparator
	 */
	List<Double> objectiveList;

	public MultiObjectiveObject() {
	}

	public MultiObjectiveObject(double d) {
		objectiveList = new ArrayList();
		objectiveList.add(d);
	}

	
	
	public List<Double> getObjectiveList() {
		return objectiveList;
	}

	public void setObjectiveList(List<Double> objectiveList) {
		this.objectiveList = objectiveList;
	}

	public int compare(MultiObjectiveObject moo){
		for(int i=0;i<this.objectiveList.size();i++){
			double d1 = (Double)this.objectiveList.get(i);
			double d2 = (Double)moo.objectiveList.get(i);
			if(d1<d2){
				return -1;
			}
			if(d1>d2){
				return 1;
			}
			
		}
		return 0;
		/*int largerNum = 0;
		int smallerNum = 0;
		int equalNum = 0;
		for(int i=0;i<this.objectiveList.size();i++){
			double d1 = (Double)this.objectiveList.get(i);
			double d2 = (Double)moo.objectiveList.get(i);
			if(d1<d2){
				smallerNum++;
			}
			if(d1>d2){
				largerNum++;
			}
			
		}
		
		if(largerNum>0 && smallerNum ==0){
			return 1;
		}
		
		if(largerNum==0 && smallerNum >0){
			return -1;
		}
		return 0;*/
	}
	
	public double distance(MultiObjectiveObject moo){
		double distance = 0.0;
		for(int i=0;i<this.objectiveList.size();i++){
			double d1 = (Double)this.objectiveList.get(i);
			double d2 = (Double)moo.objectiveList.get(i);
			distance += Math.pow((d1-d2), 2);
		}
		distance = Math.sqrt(distance);
		return distance;
	}
	
	/**
	 * given random weights, calculate the summation of multi-objective value
	 */
	public double getRandomSummation(double[] weights){
		if(weights.length != this.objectiveList.size()){
			return -1;
		}else{
			double total = 0;
			for(int i=0;i<weights.length;i++){
				total += weights[i]*((Double)objectiveList.get(i));
			}
			return total;
		}
	}
	
	/**
	 * objective minus
	 */
	public MultiObjectiveObject minus(MultiObjectiveObject mo){
		MultiObjectiveObject result = new MultiObjectiveObject();
		List l = new ArrayList();
		for(int i=0;i<mo.getObjectiveList().size();i++){
			l.add((Double)(this.getObjectiveList().get(i))-(Double)mo.getObjectiveList().get(i));
		}
		result.setObjectiveList(l);
		return result;
	}
}
